import request from "./index";
import { getRefreshToken } from "../utils/auth";
import { Base64 } from "js-base64";

export function Login(data) {
  return request({
    url: `/bspallas-admin/admin/login`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}

export function getRSAKey(data) {
  return request({
    url: `/bspallas-admin/admin/generateRSAKey`,
    method: "get",
    params: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

export function loginCheck(data) {
  return request({
    url: `/Login3`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
/***
 * 根据账号获取用户信息
 */
///bspallas-admin/admin/loadByUsername
export function getUserInfoByUsername(username) {
  return request({
    url: `/bspallas-admin/admin/loadByUsername`,
    method: "get",
    params: { username },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 获取当前用户信息
 */
export function getUserInfo() {
  return request({
    url: `/bspallas-admin/admin/getCurrentUser`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
/***
 * 登出
 */
export function logout() {
  return request({
    url: `/bspallas-admin/admin/logout`,
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 修改密码
 */

export function changePSW(data) {
  return request({
    url: `/bspallas-admin/admin/changePassword`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 * 解除账号锁定
 * @param userId  人员id
 */
export const unlockAccount = userId => {
  return request({
    url: "/bspallas-admin/admin/unlockAccount",
    method: "post",
    params: { userId },
    headers: {
      contentType: "application/x-www-form-urlencoded"
    }
  });
};

/********ukey解锁相关接口开始*************/
/**
 * 获取UK证书解锁随机码
 * */
export function getUnlockCode() {
  return request({
    url: `/bspallas-admin/cert/unlockCa`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 * 获取解密验证码
 * */
export function getVerifyCode(unlockCode) {
  return request({
    url: `/bspallas-admin/cert/unlockCheckCode`,
    method: "get",
    params: { unlockCode },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 * 判断验证码与随机码是否相同
 * */

export function judgeUnlockCode(unlockCode, checkCode) {
  return request({
    url: `/bspallas-admin/cert/judgeUnlockCode`,
    method: "get",
    params: { checkCode, unlockCode },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/********ukey解锁相关接口结束*************/
/***
 * 获取菜单树
 */
export function getMenu() {
  return request({
    url: `/bspallas-admin/menu/treeList`,
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 查询最常使用菜单
 */
export function listMoreUseMenu() {
  return request({
    url: `/bspallas-admin/menu/listMoreUseMenu`,
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 获取最近使用菜单树
 */
export function getRecentMenu() {
  return request({
    url: `/bspallas-admin/menu/listRecentMenu`,
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 * 增加最近使用菜单树
 */

export function addRecentMenu(data) {
  return request({
    url: `/bspallas-admin/menu/addUsedMenusCount`,
    method: "post",
    data: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 获取登录用户可进入的项目树
 */
export function getProjTree(data) {
  return request({
    url: `/bspallas-admin/projpact/listEnterProj`,
    method: "post",
    params: data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
/***
 * 获取登录用户可进入的标段树
 */
export function getContactTree(projId) {
  return request({
    url: `/bspallas-admin/projpact/listEnterPact`,
    method: "post",
    params: { projId },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
/***
 * 进入标段
 */
export function enterPact(pactId) {
  return request({
    url: `/bspallas-admin/projpact/enterPact`,
    method: "post",
    params: { pactId },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 查询用户身份切换列表
 */
export function listUserIdentity() {
  return request({
    url: `/bspallas-admin/projpact/listUserIdentity`,
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/***
 * 进入标段
 */

export function switchUserIdentity(data) {
  return request({
    url: `/bspallas-admin/projpact/switchUserIdentity`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}

/**
 *WBS树
 */
export function getWBS(wbsType) {
  return request({
    url: `/bspallas-quality/commondata/treeWbs`,
    method: "get",
    params: { wbsType },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

//加载所有wbs节点
export function getAllWbs(data) {
  return request({
    url: `/bspallas-quality/commondata/getAllWbs`,
    method: "get",
    params: { ...data },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 *WBS树 分层获取
 */
export function getLayerWbs(wbsId) {
  return request({
    url: `/bspallas-quality/commondata/layerWbs`,
    method: "get",
    params: { wbsId },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 *一体化平台ProjId、WbsId获取
 */
export function getYthId(projId, wbsId) {
  return request({
    url: `/bspallas-quality/wbs/query/getYthId`,
    method: "post",
    data: { projId, wbsId },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 *构建工序列表
 */

export function getProjCell(data) {
  return request({
    url: `/bspallas-quality/qualityForm/query/listProjCell`,
    method: "post",
    data: data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
}

/**
 *需要填写的表格
 */

export function getNeedFillForm(data) {
  return request({
    url: `/bspallas-quality/qualityForm/query/treeProjCellNeedFillForm`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}

/**
 *已填写的表格
 */

export function getFilledForm(data) {
  return request({
    url: `/bspallas-quality/qualityForm/query/listHaveFillForm`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}

/**刷新token */
export function refreshToken() {
  const refreshToken = getRefreshToken();
  const data = { refreshToken };
  return request({
    url: `/bspallas-admin/admin/refreshToken`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 通用下拉框类型接口
export function getPullType(tableId) {
  return request({
    url: `/bspallas-quality/commondata/getPullType`,
    method: "get",
    params: { tableId },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
// 通用下拉框数据接口
export function getPullInfo(type) {
  return request({
    url: `/bspallas-quality/commondata/getPullInfo`,
    method: "get",
    params: { type },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/**
 * 表格类型
 */
export function getTableType() {
  return request({
    url: "/bspallas-quality/dict/listTableType",
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/********桩基础页面接口开始*************/
/**
 *需要桩基搜索条件
 */

//桩基页面搜索接口
export function getZJData(data) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/getList`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}
//桩基页面新增接口
export function ZJadd(data) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/add`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}
//桩基页面新增接口
export function ZJupdate(data) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/update`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}
// 桩基施工单位接口
export function getUnitIds() {
  return request({
    url: `/bspallas-quality/commondata/getUnitIds`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 删除桩基信息接口
export function delZJData(kid) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/delete`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
// 删除桩基信息接口
export function undelZJData(kid) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/unDelete`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
// 节审定审桩基信息接口
export function signed(kid, signed) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/signed`,
    method: "post",
    params: {
      kid,
      signed
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 桩基结构物名称
export function bridgeNameTreeData() {
  return request({
    url: `/bspallas-quality/pielBasicInfo/bridgeNameTree`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 相关表格
export function basicassociatedLists(kid) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/associatedLists`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 上传证明文件后调用修改FileNumbers
export function plusFileNumbers(kid) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/plusFileNumbers`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 删除证明文件后调用修改FileNumbers
export function reduceFileNumbers(kid) {
  return request({
    url: `/bspallas-quality/pielBasicInfo/reduceFileNumbers`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

/********桩基础页面接口结束*************/

/********测量控制点接口开始*************/
/**
 *需要测量控制点搜索条件
 */

//测量控制点页面搜索接口
export function getCLData(data) {
  return request({
    url: `/bspallas-quality/measureMonitor/getList`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}
// 测量控制点分类下拉列表
export function typeIdPull() {
  return request({
    url: `/bspallas-quality/measureMonitor/typeIdPull`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
// 测量控制点性质下拉列表
export function dimensionIDPull() {
  return request({
    url: `/bspallas-quality/measureMonitor/dimensionIDPull`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
//测量控制新增接口
export function CLadd(data) {
  return request({
    url: `/bspallas-quality/measureMonitor/add`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}
//测量控制编辑接口
export function CLupdate(data) {
  return request({
    url: `/bspallas-quality/measureMonitor/update`,
    method: "post",
    data,
    headers: {
      "Content-Type": "application/json"
    }
  });
}
// 删除测量控制接口
export function delCLData(kid) {
  return request({
    url: `/bspallas-quality/measureMonitor/delete`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
// 恢复测量控制接口
export function undelCLData(kid) {
  return request({
    url: `/bspallas-quality/measureMonitor/unDelete`,
    method: "post",
    params: { kid },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
// 测量控制点模板接口
export function downLoadMeasure0203MTemplate() {
  return request({
    url: `/bspallas-quality/measureMonitor/downLoadMeasure0203MTemplate`,
    method: "get",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    responseType: "blob"
  });
}

// 相关表格
export function associatedLists(selfID) {
  return request({
    url: `/bspallas-quality/measureMonitor/associatedLists`,
    method: "post",
    params: { selfID },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}
/********测量控制点接口结束*************/

/********附件通用接口开始*************/

// 查询表格列表
export function fileList(
  fileTalbe,
  recordID,
  catalog,
  tableID,
  seqNum,
  flag,
  wbsId,
  cellId,
  cellName
) {
  return request({
    url: `/bspallas-quality/file/list`,
    method: "get",
    params: {
      fileTalbe,
      recordID,
      tableID: tableID
        ? tableID
        : JSON.parse(sessionStorage.getItem("store") || "{}").activeTabelId,
      seqNum,
      flag: seqNum || seqNum === 0 ? flag : undefined,
      wbsId,
      cellId,
      cellName
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      catalog
    }
  });
}

// 查询第三方检测报告的表格附件
export function testReportList(recordId) {
  return request({
    url: `/bspallas-quality/file/testReportList`,
    method: "get",
    params: { recordId },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    }
  });
}

// 查询多个表格附件列表
export function listBatch(fileTalbe, recordID, catalog, tableID) {
  return request({
    url: `/bspallas-quality/file/listBatch`,
    method: "post",
    data: {
      fileTalbe,
      recordIds: recordID,
      tableIds: tableID
        ? tableID
        : JSON.parse(sessionStorage.getItem("store") || "{}").activeTabelId
    },
    headers: {
      "Content-Type": "application/json",
      catalog
    }
  });
}

// 下载文件接口
export function downloadFile(data, catalog) {
  return request({
    url: `/bspallas-quality/file/download`,
    method: "post",
    data: {
      tableID: JSON.parse(sessionStorage.getItem("store") || "{}")
        .activeTabelId,
      ...data
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      catalog
    },
    responseType: "blob"
  });
}
// 上传文件接口
export function uploadFile(fileTalbe, files, recordID, tableID, catalog) {
  return request({
    url: `/bspallas-quality/file/upload`,
    method: "post",
    data: {
      fileTalbe,
      files,
      recordID,
      tableID: tableID
        ? tableID
        : JSON.parse(sessionStorage.getItem("store") || "{}").activeTabelId
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      catalog
    }
  });
}

// 第三方检测报告的表格上传附件
export function uploadTestReport(fileTalbe, files, recordID, tableID, catalog) {
  return request({
    url: `/bspallas-quality/file/testReportUpload`,
    method: "post",
    data: {
      fileTalbe,
      files,
      recordID,
      tableID: tableID
        ? tableID
        : JSON.parse(sessionStorage.getItem("store") || "{}").activeTabelId
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      catalog
    }
  });
}

//删除文件接口
export function deleteFile(fileTalbe, kids, tableId, catalog) {
  return request({
    url: `/bspallas-quality/file/delete`,
    method: "post",
    data: {
      fileTalbe,
      kids,
      tableId: tableId
        ? tableId
        : JSON.parse(sessionStorage.getItem("store") || "{}").activeTabelId
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      catalog
    }
  });
}

//查看文件接口
export function onlinePreview(
  fileTalbe,
  kids,
  title,
  tableId,
  catalog,
  isBase64 = true
) {
  const titleB64 = isBase64 ? Base64.encode(title) : title;
  return request({
    url: `/bspallas-quality/file/onlinePreview`,
    method: "post",
    params: {
      kids,
      title: titleB64,
      fileTalbe,
      tableId: tableId
        ? tableId
        : JSON.parse(sessionStorage.getItem("store") || "{}").activeTabelId
    },
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
      catalog
    }
  });
}

//根据url进行下载
export function downloadForUrl(url) {
  return request({
    url: `/bspallas-quality/file/downloadForUrl`,
    method: "post",
    params: { url },
    responseType: "blob"
  });
}
/********附件通用接口开始*************/
